<!--
Copyright Louis Dionne 2013-2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
-->
<!-- boost-no-inspect -->
<!-- HTML header for doxygen 1.8.9.1-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<title>Boost.Hana: Comparable</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(function() { init_search(); });
/* @license-end */
</script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
MathJax.Hub.Config({
    "HTML-CSS": {
        linebreaks: {
            automatic: true,
            width: "75% container"
        }
    }
});
</script>
<script type="text/javascript" async="async" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<!-- Additional javascript for drawing charts. -->
<script type="text/javascript" src="highcharts.js"></script>
<script type="text/javascript" src="highcharts-data.js"></script>
<script type="text/javascript" src="highcharts-exporting.js"></script>
<script type="text/javascript" src="chart.js"></script>
<script type="text/javascript" src="hana.js"></script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="Boost.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">Boost.Hana
   &#160;<span id="projectnumber">1.7.1</span>
   </div>
   <div id="projectbrief">Your standard library for metaprogramming</div>
  </td>
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.svg"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('group__group-_comparable.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#var-members">Variables</a>  </div>
  <div class="headertitle">
<div class="title">Comparable<div class="ingroups"><a class="el" href="group__group-concepts.html">Concepts</a></div></div>  </div>
</div><!--header-->
<div class="contents">
<a name="details" id="details"></a><h2 class="groupheader">Description</h2>
<p>The <code>Comparable</code> concept defines equality and inequality. </p>
<p>Intuitively, <code>Comparable</code> objects must define a binary predicate named <code>equal</code> that returns whether both objects represent the same abstract value. In other words, <code>equal</code> must check for deep equality. Since "representing the same abstract value" is difficult to express formally, the exact meaning of equality is partially left to interpretation by the programmer with the following guidelines:<br  />
</p><ol type="1">
<li>Equality should be compatible with copy construction; copy constructing a value yields an <code>equal</code> value.</li>
<li>Equality should be independent of representation; an object representing a fraction as <code>4/8</code> should be <code>equal</code> to an object representing a fraction as <code>2/4</code>, because they both represent the mathematical object <code>1/2</code>.</li>
</ol>
<p>Moreover, <code>equal</code> must exhibit properties that make it intuitive to use for determining the equivalence of objects, which is formalized by the laws for <code>Comparable</code>.</p>
<h2><a class="anchor" id="autotoc_md81"></a>
Minimal complete definition</h2>
<ol type="1">
<li><code>equal</code><br  />
When <code>equal</code> is defined, <code>not_equal</code> is implemented by default as its complement. For all objects <code>x</code>, <code>y</code> of a <code>Comparable</code> tag, <div class="fragment"><div class="line"><a class="code" href="group__group-_comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">not_equal</a>(x, y) == <a class="code" href="group__group-_logical.html#ga4a7c9d7037601d5e553fd20777958980">not_</a>(<a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(x, y))</div>
<div class="ttc" id="agroup__group-_comparable_html_gacaf1ebea6b3ab96ac9dcb82f0e64e547"><div class="ttname"><a href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">boost::hana::equal</a></div><div class="ttdeci">constexpr auto equal</div><div class="ttdoc">Returns a Logical representing whether x is equal to y.</div><div class="ttdef"><b>Definition:</b> equal.hpp:64</div></div>
<div class="ttc" id="agroup__group-_comparable_html_gae33be2e0d5e04f19082f4b7740dfc9cd"><div class="ttname"><a href="group__group-_comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">boost::hana::not_equal</a></div><div class="ttdeci">constexpr auto not_equal</div><div class="ttdoc">Returns a Logical representing whether x is not equal to y.</div><div class="ttdef"><b>Definition:</b> not_equal.hpp:54</div></div>
<div class="ttc" id="agroup__group-_logical_html_ga4a7c9d7037601d5e553fd20777958980"><div class="ttname"><a href="group__group-_logical.html#ga4a7c9d7037601d5e553fd20777958980">boost::hana::not_</a></div><div class="ttdeci">constexpr auto not_</div><div class="ttdoc">Negates a Logical.</div><div class="ttdef"><b>Definition:</b> not.hpp:31</div></div>
</div><!-- fragment --></li>
</ol>
<h2><a class="anchor" id="autotoc_md82"></a>
Laws</h2>
<p><code>equal</code> must define an <a href="http://en.wikipedia.org/wiki/Equivalence_relation#Definition">equivalence relation</a>, and <code>not_equal</code> must be its complement. In other words, for all objects <code>a</code>, <code>b</code>, <code>c</code> with a <code>Comparable</code> tag, the following must hold: </p><div class="fragment"><div class="line"><a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(a, a)                                         <span class="comment">// Reflexivity</span></div>
<div class="line"><span class="keywordflow">if</span> <a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(a, b) <a class="code" href="group__group-_monad.html#gaaddd3789de43cf989babb10cdc0b447a">then</a> <a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(b, a)                     <span class="comment">// Symmetry</span></div>
<div class="line"><span class="keywordflow">if</span> <a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(a, b) &amp;&amp; <a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(b, c) <a class="code" href="group__group-_monad.html#gaaddd3789de43cf989babb10cdc0b447a">then</a> <a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(a, c)      <span class="comment">// Transitivity</span></div>
<div class="line"><a class="code" href="group__group-_comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">not_equal</a>(a, b) is equivalent <a class="code" href="group__group-core.html#gadc70755c1d059139297814fb3bfeb91e">to</a> <a class="code" href="group__group-_logical.html#ga4a7c9d7037601d5e553fd20777958980">not_</a>(<a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(a, b))</div>
<div class="ttc" id="agroup__group-_monad_html_gaaddd3789de43cf989babb10cdc0b447a"><div class="ttname"><a href="group__group-_monad.html#gaaddd3789de43cf989babb10cdc0b447a">boost::hana::then</a></div><div class="ttdeci">constexpr auto then</div><div class="ttdoc">Sequentially compose two monadic actions, discarding any value produced by the first but not its effe...</div><div class="ttdef"><b>Definition:</b> then.hpp:36</div></div>
<div class="ttc" id="agroup__group-core_html_gadc70755c1d059139297814fb3bfeb91e"><div class="ttname"><a href="group__group-core.html#gadc70755c1d059139297814fb3bfeb91e">boost::hana::to</a></div><div class="ttdeci">constexpr auto to</div><div class="ttdoc">Converts an object from one data type to another.</div><div class="ttdef"><b>Definition:</b> to.hpp:97</div></div>
</div><!-- fragment --><h2><a class="anchor" id="autotoc_md83"></a>
Concrete models</h2>
<p><code><a class="el" href="structboost_1_1hana_1_1integral__constant.html" title="Compile-time value of an integral type.">hana::integral_constant</a></code>, <code><a class="el" href="structboost_1_1hana_1_1map.html" title="Basic associative container requiring unique, Comparable and Hashable keys.">hana::map</a></code>, <code><a class="el" href="structboost_1_1hana_1_1optional.html" title="Optional value whose optional-ness is known at compile-time.">hana::optional</a></code>, <code><a class="el" href="structboost_1_1hana_1_1pair.html" title="Generic container for two elements.">hana::pair</a></code>, <code><a class="el" href="structboost_1_1hana_1_1range.html" title="Compile-time half-open interval of hana::integral_constants.">hana::range</a></code>, <code><a class="el" href="structboost_1_1hana_1_1set.html" title="Basic unordered container requiring unique, Comparable and Hashable keys.">hana::set</a></code>, <code><a class="el" href="structboost_1_1hana_1_1string.html" title="Compile-time string.">hana::string</a></code>, <code><a class="el" href="structboost_1_1hana_1_1tuple.html" title="General purpose index-based heterogeneous sequence with a fixed length.">hana::tuple</a></code>, <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code></p>
<h2><a class="anchor" id="autotoc_md84"></a>
Free model for &lt;tt&gt;EqualityComparable&lt;/tt&gt; data types</h2>
<p>Two data types <code>T</code> and <code>U</code> that model the cross-type EqualityComparable concept presented in <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3351.pdf">N3351</a> automatically model the <code>Comparable</code> concept by setting </p><div class="fragment"><div class="line"><a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(x, y) = (x == y)</div>
</div><!-- fragment --><p> Note that this also makes EqualityComparable types in the <a href="http://en.cppreference.com/w/cpp/named_req/EqualityComparable">usual sense</a> models of <code>Comparable</code> in the same way.</p>
<h2><a class="anchor" id="autotoc_md85"></a>
Equality-preserving functions</h2>
<p>Let <code>A</code> and <code>B</code> be two <code>Comparable</code> tags. A function \(f : A \to B\) is said to be equality-preserving if it preserves the structure of the <code>Comparable</code> concept, which can be rigorously stated as follows. For all objects <code>x</code>, <code>y</code> of tag <code>A</code>, </p><div class="fragment"><div class="line"><span class="keywordflow">if</span>  <a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(x, y)  <a class="code" href="group__group-_monad.html#gaaddd3789de43cf989babb10cdc0b447a">then</a>  <a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(f(x), f(y))</div>
</div><!-- fragment --><p> Equivalently, we simply require that <code>f</code> is a function in the usual mathematical sense. Another property is <a href="http://en.wikipedia.org/wiki/Injective_function">injectivity</a>, which can be viewed as being a "lossless" mapping. This property can be stated as </p><div class="fragment"><div class="line"><span class="keywordflow">if</span>  <a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(f(x), f(y))  <a class="code" href="group__group-_monad.html#gaaddd3789de43cf989babb10cdc0b447a">then</a>  <a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(x, y)</div>
</div><!-- fragment --><p> This is equivalent to saying that <code>f</code> maps distinct elements to distinct elements, hence the "lossless" analogy. In other words, <code>f</code> will not collapse distinct elements from its domain into a single element in its image, thus losing information.</p>
<p>These functions are very important, especially equality-preserving ones, because they allow us to reason simply about programs. Also note that the property of being equality-preserving is taken for granted in mathematics because it is part of the definition of a function. We feel it is important to make the distinction here because programming has evolved differently and as a result programmers are used to work with functions that do not preserve equality.</p>
<h2><a class="anchor" id="autotoc_md86"></a>
Cross-type version of the methods</h2>
<p>The <code>equal</code> and <code>not_equal</code> methods are "overloaded" to handle distinct tags with certain properties. Specifically, they are defined for <em>distinct</em> tags <code>A</code> and <code>B</code> such that</p><ol type="1">
<li><code>A</code> and <code>B</code> share a common tag <code>C</code>, as determined by the <code>common</code> metafunction</li>
<li><code>A</code>, <code>B</code> and <code>C</code> are all <code>Comparable</code> when taken individually</li>
<li>\( \mathtt{to&lt;C&gt;} : A \to C \) and \(\mathtt{to&lt;C&gt;} : B \to C\) are both equality-preserving and injective (i.e. they are embeddings), as determined by the <code>is_embedding</code> metafunction.</li>
</ol>
<p>The method definitions for tags satisfying the above properties are </p><div class="fragment"><div class="line"><a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(x, y)     = <a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(to&lt;C&gt;(x), to&lt;C&gt;(y))</div>
<div class="line"><a class="code" href="group__group-_comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">not_equal</a>(x, y) = <a class="code" href="group__group-_comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">not_equal</a>(to&lt;C&gt;(x), to&lt;C&gt;(y))</div>
</div><!-- fragment --><h2><a class="anchor" id="autotoc_md87"></a>
Important note: special behavior of &lt;tt&gt;equal&lt;/tt&gt;</h2>
<p>In the context of programming with heterogeneous values, it is useful to have unrelated objects compare <code>false</code> instead of triggering an error. For this reason, <code>equal</code> adopts a special behavior for unrelated objects of tags <code>T</code> and <code>U</code> that do not satisfy the above requirements for the cross-type overloads. Specifically, when <code>T</code> and <code>U</code> are unrelated (i.e. <code>T</code> can't be converted to <code>U</code> and vice-versa), comparing objects with those tags yields a compile-time false value. This has the effect that unrelated objects like <code>float</code> and <code>std::string</code> will compare false, while comparing related objects that can not be safely embedded into the same super structure (like <code>long long</code> and <code>float</code> because of the precision loss) will trigger a compile-time assertion. Also note that for any tag <code>T</code> for which the minimal complete definition of <code>Comparable</code> is not provided, a compile-time assertion will also be triggered because <code>T</code> and <code>T</code> trivially share the common tag <code>T</code>, which is the expected behavior. This design choice aims to provide more flexibility for comparing objects, while still rejecting usage patterns that are most likely programming errors. </p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="var-members"></a>
Variables</h2></td></tr>
<tr class="memitem:ga9c2ffe2e51780e57a38d9e7e31b87cdc"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-_comparable.html#ga9c2ffe2e51780e57a38d9e7e31b87cdc">boost::hana::comparing</a></td></tr>
<tr class="memdesc:ga9c2ffe2e51780e57a38d9e7e31b87cdc"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a function performing <code>equal</code> after applying a transformation to both arguments.  <a href="group__group-_comparable.html#ga9c2ffe2e51780e57a38d9e7e31b87cdc">More...</a><br /></td></tr>
<tr class="separator:ga9c2ffe2e51780e57a38d9e7e31b87cdc"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gacaf1ebea6b3ab96ac9dcb82f0e64e547"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">boost::hana::equal</a></td></tr>
<tr class="memdesc:gacaf1ebea6b3ab96ac9dcb82f0e64e547"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a <code>Logical</code> representing whether <code>x</code> is equal to <code>y</code>.  <a href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">More...</a><br /></td></tr>
<tr class="separator:gacaf1ebea6b3ab96ac9dcb82f0e64e547"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gae33be2e0d5e04f19082f4b7740dfc9cd"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-_comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">boost::hana::not_equal</a></td></tr>
<tr class="memdesc:gae33be2e0d5e04f19082f4b7740dfc9cd"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a <code>Logical</code> representing whether <code>x</code> is not equal to <code>y</code>.  <a href="group__group-_comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">More...</a><br /></td></tr>
<tr class="separator:gae33be2e0d5e04f19082f4b7740dfc9cd"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<h2 class="groupheader">Variable Documentation</h2>
<a id="ga9c2ffe2e51780e57a38d9e7e31b87cdc"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga9c2ffe2e51780e57a38d9e7e31b87cdc">&#9670;&nbsp;</a></span>comparing</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">constexpr auto boost::hana::comparing</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">constexpr</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="fwd_2comparing_8hpp.html">boost/hana/fwd/comparing.hpp</a>&gt;</code></p>
<b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; f) {</div>
<div class="line">        <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; x, <span class="keyword">auto</span>&amp;&amp; y) {</div>
<div class="line">            <span class="keywordflow">return</span> <a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(f(forwarded(x)), f(forwarded(y)));</div>
<div class="line">        };</div>
<div class="line">    }</div>
<div class="ttc" id="agroup__group-functional_html_ga41ada6b336e9d5bcb101ff0c737acbd0"><div class="ttname"><a href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">boost::hana::capture</a></div><div class="ttdeci">constexpr auto capture</div><div class="ttdoc">Create a function capturing the given variables.</div><div class="ttdef"><b>Definition:</b> capture.hpp:45</div></div>
</div><!-- fragment -->
<p>Returns a function performing <code>equal</code> after applying a transformation to both arguments. </p>
<p><code>comparing</code> creates an equivalence relation based on the result of applying a function to some objects, which is especially useful in conjunction with algorithms that accept a custom predicate that must represent an equivalence relation.</p>
<p>Specifically, <code>comparing</code> is such that </p><div class="fragment"><div class="line"><a class="code" href="group__group-_comparable.html#ga9c2ffe2e51780e57a38d9e7e31b87cdc">comparing</a>(f) == <a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a> ^<a class="code" href="group__group-functional.html#ga35c4fc3c5677b9f558150b90e74d3ab1">on</a>^ f</div>
<div class="ttc" id="agroup__group-_comparable_html_ga9c2ffe2e51780e57a38d9e7e31b87cdc"><div class="ttname"><a href="group__group-_comparable.html#ga9c2ffe2e51780e57a38d9e7e31b87cdc">boost::hana::comparing</a></div><div class="ttdeci">constexpr auto comparing</div><div class="ttdoc">Returns a function performing equal after applying a transformation to both arguments.</div><div class="ttdef"><b>Definition:</b> comparing.hpp:50</div></div>
<div class="ttc" id="agroup__group-functional_html_ga35c4fc3c5677b9f558150b90e74d3ab1"><div class="ttname"><a href="group__group-functional.html#ga35c4fc3c5677b9f558150b90e74d3ab1">boost::hana::on</a></div><div class="ttdeci">constexpr auto on</div><div class="ttdoc">Invoke a function with the result of invoking another function on each argument.</div><div class="ttdef"><b>Definition:</b> on.hpp:54</div></div>
</div><!-- fragment --><p> or, equivalently, </p><div class="fragment"><div class="line"><a class="code" href="group__group-_comparable.html#ga9c2ffe2e51780e57a38d9e7e31b87cdc">comparing</a>(f)(x, y) == <a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(f(x), f(y))</div>
</div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>This is not a tag-dispatched method (hence it can't be customized), but just a convenience function provided with the <code>Comparable</code> concept.</dd></dl>
<h2><a class="anchor" id="autotoc_md68"></a>
Signature</h2>
<p>Given a Logical <code>Bool</code> and a Comparable <code>B</code>, the signature is \( \mathtt{comparing} : (A \to B) \to (A \times A \to Bool) \).</p>
<h2><a class="anchor" id="autotoc_md69"></a>
Example</h2>
<div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div>
<div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div>
<div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="comparing_8hpp.html">boost/hana/comparing.hpp</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="group_8hpp.html">boost/hana/group.hpp</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="length_8hpp.html">boost/hana/length.hpp</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="range_8hpp.html">boost/hana/range.hpp</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="tuple_8hpp.html">boost/hana/tuple.hpp</a>&gt;</span></div>
<div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main() {</div>
<div class="line">    constexpr <span class="keyword">auto</span> sequences = hana::make_tuple(</div>
<div class="line">        hana::make_tuple(1, 2, 3),</div>
<div class="line">        hana::make_tuple(<span class="charliteral">&#39;x&#39;</span>, <span class="charliteral">&#39;y&#39;</span>, <span class="charliteral">&#39;z&#39;</span>),</div>
<div class="line">        hana::range_c&lt;long, 0, 1&gt;,</div>
<div class="line">        hana::tuple_t&lt;char, int&gt;,</div>
<div class="line">        hana::range_c&lt;int, 0, 2&gt;,</div>
<div class="line">        hana::make_tuple(123.4, <span class="keyword">nullptr</span>)</div>
<div class="line">    );</div>
<div class="line"> </div>
<div class="line">    constexpr <span class="keyword">auto</span> grouped = hana::group.by(<a class="code" href="group__group-_comparable.html#ga9c2ffe2e51780e57a38d9e7e31b87cdc">hana::comparing</a>(<a class="code" href="group__group-_foldable.html#gaf0f8f717245620dc28cd7d7fa44d7475">hana::length</a>), sequences);</div>
<div class="line"> </div>
<div class="line">    static_assert(grouped == hana::make_tuple(</div>
<div class="line">        hana::make_tuple(</div>
<div class="line">            hana::make_tuple(1, 2, 3),</div>
<div class="line">            hana::make_tuple(<span class="charliteral">&#39;x&#39;</span>, <span class="charliteral">&#39;y&#39;</span>, <span class="charliteral">&#39;z&#39;</span>)</div>
<div class="line">        ),</div>
<div class="line">        hana::make_tuple(</div>
<div class="line">            hana::range_c&lt;long, 0, 1&gt;</div>
<div class="line">        ),</div>
<div class="line">        hana::make_tuple(</div>
<div class="line">            hana::tuple_t&lt;char, int&gt;,</div>
<div class="line">            hana::range_c&lt;int, 0, 2&gt;,</div>
<div class="line">            hana::make_tuple(123.4, <span class="keyword">nullptr</span>)</div>
<div class="line">        )</div>
<div class="line">    ), <span class="stringliteral">&quot;&quot;</span>);</div>
<div class="line">}</div>
<div class="ttc" id="acomparing_8hpp_html"><div class="ttname"><a href="comparing_8hpp.html">comparing.hpp</a></div><div class="ttdoc">Defines boost::hana::comparing.</div></div>
<div class="ttc" id="aequal_8hpp_html"><div class="ttname"><a href="equal_8hpp.html">equal.hpp</a></div><div class="ttdoc">Defines boost::hana::equal.</div></div>
<div class="ttc" id="agroup_8hpp_html"><div class="ttname"><a href="group_8hpp.html">group.hpp</a></div><div class="ttdoc">Defines boost::hana::group.</div></div>
<div class="ttc" id="agroup__group-_foldable_html_gaf0f8f717245620dc28cd7d7fa44d7475"><div class="ttname"><a href="group__group-_foldable.html#gaf0f8f717245620dc28cd7d7fa44d7475">boost::hana::length</a></div><div class="ttdeci">constexpr auto length</div><div class="ttdoc">Return the number of elements in a foldable structure.</div><div class="ttdef"><b>Definition:</b> length.hpp:34</div></div>
<div class="ttc" id="alength_8hpp_html"><div class="ttname"><a href="length_8hpp.html">length.hpp</a></div><div class="ttdoc">Defines boost::hana::length.</div></div>
<div class="ttc" id="anamespaceboost_1_1hana_html"><div class="ttname"><a href="namespaceboost_1_1hana.html">boost::hana</a></div><div class="ttdoc">Namespace containing everything in the library.</div><div class="ttdef"><b>Definition:</b> accessors.hpp:20</div></div>
<div class="ttc" id="arange_8hpp_html"><div class="ttname"><a href="range_8hpp.html">range.hpp</a></div><div class="ttdoc">Defines boost::hana::range.</div></div>
<div class="ttc" id="atuple_8hpp_html"><div class="ttname"><a href="tuple_8hpp.html">tuple.hpp</a></div><div class="ttdoc">Defines boost::hana::tuple.</div></div>
</div><!-- fragment --> 
</div>
</div>
<a id="gacaf1ebea6b3ab96ac9dcb82f0e64e547"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gacaf1ebea6b3ab96ac9dcb82f0e64e547">&#9670;&nbsp;</a></span>equal</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">constexpr auto boost::hana::equal</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">constexpr</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="fwd_2equal_8hpp.html">boost/hana/fwd/equal.hpp</a>&gt;</code></p>
<b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; x, <span class="keyword">auto</span>&amp;&amp; y) {</div>
<div class="line">        <span class="keywordflow">return</span> tag-dispatched;</div>
<div class="line">    }</div>
</div><!-- fragment -->
<p>Returns a <code>Logical</code> representing whether <code>x</code> is equal to <code>y</code>. </p>
<p>The <code>equal</code> function can be called in two different ways. First, it can be called like a normal function: </p><div class="fragment"><div class="line"><a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(x, y)</div>
</div><!-- fragment --><p>However, it may also be partially applied to an argument by using <code>equal.to</code>: </p><div class="fragment"><div class="line"><a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>.to(x)(y) == <a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(x, y)</div>
</div><!-- fragment --><p>In other words, <code>equal.to(x)</code> is a function object that is equivalent to <code>partial(equal, x)</code>. This is provided to enhance the readability of some constructs, especially when using higher order algorithms.</p>
<h2><a class="anchor" id="autotoc_md212"></a>
Signature</h2>
<p>Given a Logical <code>Bool</code> and two Comparables <code>A</code> and <code>B</code> that share a common embedding, the signature is \( \mathtt{equal} : A \times B \to Bool \).</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">x,y</td><td>Two objects to compare for equality.</td></tr>
  </table>
  </dd>
</dl>
<h2><a class="anchor" id="autotoc_md213"></a>
Example</h2>
<div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div>
<div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div>
<div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="any__of_8hpp.html">boost/hana/any_of.hpp</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="tuple_8hpp.html">boost/hana/tuple.hpp</a>&gt;</span></div>
<div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main() {</div>
<div class="line">    static_assert(<a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">hana::equal</a>(hana::make_tuple(1, 2), hana::make_tuple(1, 2)), <span class="stringliteral">&quot;&quot;</span>);</div>
<div class="line">    static_assert(!<a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">hana::equal</a>(<span class="charliteral">&#39;x&#39;</span>, <span class="charliteral">&#39;y&#39;</span>), <span class="stringliteral">&quot;&quot;</span>);</div>
<div class="line">    <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(!<a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">hana::equal</a>(hana::make_tuple(1, 2), <span class="charliteral">&#39;y&#39;</span>));</div>
<div class="line"> </div>
<div class="line">    static_assert(<a class="code" href="group__group-_searchable.html#ga5f7ff0125c448983e1b96c3ffb84f646">hana::any_of</a>(hana::make_tuple(1, 2, 3), <a class="code" href="group__group-_comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">hana::equal</a>.<a class="code" href="group__group-core.html#gadc70755c1d059139297814fb3bfeb91e">to</a>(2)), <span class="stringliteral">&quot;&quot;</span>);</div>
<div class="line">}</div>
<div class="ttc" id="aany__of_8hpp_html"><div class="ttname"><a href="any__of_8hpp.html">any_of.hpp</a></div><div class="ttdoc">Defines boost::hana::any_of.</div></div>
<div class="ttc" id="aassert_8hpp_html"><div class="ttname"><a href="assert_8hpp.html">assert.hpp</a></div><div class="ttdoc">Defines macros to perform different kinds of assertions.</div></div>
<div class="ttc" id="agroup__group-_searchable_html_ga5f7ff0125c448983e1b96c3ffb84f646"><div class="ttname"><a href="group__group-_searchable.html#ga5f7ff0125c448983e1b96c3ffb84f646">boost::hana::any_of</a></div><div class="ttdeci">constexpr auto any_of</div><div class="ttdoc">Returns whether any key of the structure satisfies the predicate.</div><div class="ttdef"><b>Definition:</b> any_of.hpp:37</div></div>
<div class="ttc" id="agroup__group-assertions_html_ga2c5006540936d9f8880e3a39f4fcc035"><div class="ttname"><a href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a></div><div class="ttdeci">#define BOOST_HANA_CONSTANT_CHECK(...)</div><div class="ttdoc">Equivalent to BOOST_HANA_CONSTANT_ASSERT, but not influenced by the BOOST_HANA_CONFIG_DISABLE_ASSERTI...</div><div class="ttdef"><b>Definition:</b> assert.hpp:239</div></div>
</div><!-- fragment --><blockquote class="doxtable">
<p>#### Rationale for the arity of <code>equal</code> It is a valid question whether <code>equal</code> should accept more than 2 arguments and have semantics matching those of Python's <code>==</code>. This is not supported right now for the following reasons:</p><ul>
<li>It was implemented in the MPL11, but it was not shown to be useful so far.</li>
<li>It does not make sense for <code>not_equal</code> to have an arity of more than 2, only <code>equal</code> could maybe have those semantics, which would break symmetry. </li>
</ul>
</blockquote>

</div>
</div>
<a id="gae33be2e0d5e04f19082f4b7740dfc9cd"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gae33be2e0d5e04f19082f4b7740dfc9cd">&#9670;&nbsp;</a></span>not_equal</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">constexpr auto boost::hana::not_equal</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">constexpr</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="fwd_2not__equal_8hpp.html">boost/hana/fwd/not_equal.hpp</a>&gt;</code></p>
<b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; x, <span class="keyword">auto</span>&amp;&amp; y) {</div>
<div class="line">        <span class="keywordflow">return</span> tag-dispatched;</div>
<div class="line">    }</div>
</div><!-- fragment -->
<p>Returns a <code>Logical</code> representing whether <code>x</code> is not equal to <code>y</code>. </p>
<p>The <code>not_equal</code> function can be called in two different ways. First, it can be called like a normal function: </p><div class="fragment"><div class="line"><a class="code" href="group__group-_comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">not_equal</a>(x, y)</div>
</div><!-- fragment --><p>However, it may also be partially applied to an argument by using <code>not_equal.to</code>: </p><div class="fragment"><div class="line"><a class="code" href="group__group-_comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">not_equal</a>.to(x)(y) == <a class="code" href="group__group-_comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">not_equal</a>(x, y)</div>
</div><!-- fragment --><p>In other words, <code>not_equal.to(x)</code> is a function object that is equivalent to <code>partial(not_equal, x)</code>. This is provided to enhance the readability of some constructs, especially when using higher order algorithms.</p>
<h2><a class="anchor" id="autotoc_md292"></a>
Signature</h2>
<p>Given a Logical <code>Bool</code> and two Comparables <code>A</code> and <code>B</code> that share a common embedding, the signature is \( \mathtt{not\_equal} : A \times B \to Bool \).</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">x,y</td><td>Two objects to compare for inequality.</td></tr>
  </table>
  </dd>
</dl>
<h2><a class="anchor" id="autotoc_md293"></a>
Example</h2>
<div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div>
<div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div>
<div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="all__of_8hpp.html">boost/hana/all_of.hpp</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="not__equal_8hpp.html">boost/hana/not_equal.hpp</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="tuple_8hpp.html">boost/hana/tuple.hpp</a>&gt;</span></div>
<div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main() {</div>
<div class="line">    static_assert(<a class="code" href="group__group-_comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">hana::not_equal</a>(hana::make_tuple(1, 2), hana::make_tuple(3)), <span class="stringliteral">&quot;&quot;</span>);</div>
<div class="line">    static_assert(<a class="code" href="group__group-_comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">hana::not_equal</a>(<span class="charliteral">&#39;x&#39;</span>, <span class="charliteral">&#39;y&#39;</span>), <span class="stringliteral">&quot;&quot;</span>);</div>
<div class="line">    <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-_comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">hana::not_equal</a>(hana::make_tuple(1, 2), <span class="charliteral">&#39;y&#39;</span>));</div>
<div class="line"> </div>
<div class="line">    static_assert(<a class="code" href="group__group-_searchable.html#ga3a168950082f38afd9edf256f336c8ba">hana::all_of</a>(hana::make_tuple(1, 2, 3), <a class="code" href="group__group-_comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">hana::not_equal</a>.<a class="code" href="group__group-core.html#gadc70755c1d059139297814fb3bfeb91e">to</a>(5)), <span class="stringliteral">&quot;&quot;</span>);</div>
<div class="line">}</div>
<div class="ttc" id="aall__of_8hpp_html"><div class="ttname"><a href="all__of_8hpp.html">all_of.hpp</a></div><div class="ttdoc">Defines boost::hana::all_of.</div></div>
<div class="ttc" id="agroup__group-_searchable_html_ga3a168950082f38afd9edf256f336c8ba"><div class="ttname"><a href="group__group-_searchable.html#ga3a168950082f38afd9edf256f336c8ba">boost::hana::all_of</a></div><div class="ttdeci">constexpr auto all_of</div><div class="ttdoc">Returns whether all the keys of the structure satisfy the predicate.</div><div class="ttdef"><b>Definition:</b> all_of.hpp:38</div></div>
<div class="ttc" id="anot__equal_8hpp_html"><div class="ttname"><a href="not__equal_8hpp.html">not_equal.hpp</a></div><div class="ttdoc">Defines boost::hana::not_equal.</div></div>
</div><!-- fragment --> 
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!--
Copyright Louis Dionne 2013-2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
-->
<!-- boost-no-inspect -->
<!-- HTML footer for doxygen 1.8.9.1-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
  </ul>
</div>
</body>
</html>
